
/*
Description:

*/

#include <iostream>
#include <string>
#include <vector>
using namespace std;

class Solution {
public:
	int removeElement(vector<int>& nums, int val) {
		int len = nums.size();
		
		for (int i = 0; i < len; i++)
		{
			if (nums[i] == val)
			{
				while (len-1 > i && nums[len - 1] == val)
				{
					len--;
				}
				if (len > 1)
				{
					nums[i] = nums[len - 1];
					len--;
				}
				else if (len == 1)
				{
					len--;
				}
			}
		}
		return len;
	}
};

int _removeElement()
{
	vector<int> nums{ 1 };// {4, 5};// { 0, 1, 2, 2, 3, 0, 4, 2 }; // { 3, 2, 2, 3 };//
	int val = 1;// 5;// 2;// 3;//
	Solution solu;
	int len;
	
	//for (auto &n : nums)
	//{
	//	n = 4;
	//}

	cout << "nums befor remove:" << endl;
	for (auto n : nums) cout << n << " ";
	cout << endl;

	cout << "value:" << val << endl;

	len = solu.removeElement(nums, val);


	cout << "len:" << len << endl;

	cout << "nums after remove:" << endl;
	for (auto i = 0; i < len; i++) cout << nums[i] << " ";
	cout << endl;

	return 0;
}